import { request } from '@/utils/request'
export const checkFCode = (goodsId, fcode) =>
  request('/memberbuy/check_fcode', {
    goods_id: goodsId,
    fcode: fcode
  })

// 获取订单信息
export const buyStep1 = (cartId, ifcart, pintuanId, pintuangroupId, extra = {}) =>
  request(
    '/memberbuy/buy_step1',
    Object.assign(
      {
        cart_id: cartId,
        ifcart: ifcart,
        pintuan_id: pintuanId,
        pintuangroup_id: pintuangroupId
      },
      extra
    )
  )

// 下单入库
export const buyStep2 = (
  ifcart,
  cartId,
  addressId,
  vatHash,
  offpayHash,
  offpayHashBatch,
  invoiceId,
  voucher,
  pdPay,
  password,
  rcbPay,
  payMessage,
  pintuanId,
  pintuangroupId,
  fCode,
  payCode,
  shareCode,
  extra = {}
) =>
  request(
    '/memberbuy/buy_step2',
    Object.assign(
      {
        ifcart: ifcart,
        cart_id: cartId,
        address_id: addressId,
        vat_hash: vatHash,
        offpay_hash: offpayHash,
        offpay_hash_batch: offpayHashBatch,
        pay_name: payCode,
        invoice_id: invoiceId,
        voucher: voucher,
        pd_pay: pdPay,
        password: password,
        rcb_pay: rcbPay,
        pay_message: payMessage,
        pintuan_id: pintuanId,
        pintuangroup_id: pintuangroupId,
        fcode: fCode,
        share_code: shareCode
      },
      extra
    )
  )

// 获取订单支付信息
export const getOrderpayInfo = paySn =>
  request('/memberbuy/pay', {
    pay_sn: paySn
  })

// 获取订单支付信息
export const getVrOrderpayInfo = paySn =>
  request('/membervrbuy/pay', {
    pay_sn: paySn
  })

// 用户支付
export const pay = (paySn, payType, data, key, openId, subOpenId) =>
  request(
    '?s=api/Memberpayment/' +
      payType +
      '/pay_sn/' +
      paySn +
      '/password/' +
      data.password +
      '/rcb_pay/' +
      data.rcb_pay +
      '/pd_pay/' +
      data.pd_pay +
      '/payment_code/' +
      data.payment_code +
      '/key/' +
      key +
      '/open_id/' +
      openId +
      '/sub_open_id/' +
      subOpenId,
    {},
    'GET'
  )

// 获取支付方式列表
export const getPaymentList = () => request('/Memberpayment/payment_list')

export const getRechargeInfo = paysn =>
  request('/Recharge/recharge_order', {
    paysn: paysn
  })

/**
 * 支付之前获取微信/支付宝授权
 * @param {*} paySn
 * @param {*} payType
 * @param {*} payWay
 */
export const payAuth = (paySn, payType, payWay) =>
  request('Paymentcode/wxAuth', { pay_sn: paySn, pay_type: payType, pay_way: payWay })
